using System;

using FineCollection.Intf;

using NUnit.Framework;




namespace FineCollection.Cont
{
    [TestFixture]
    public class HashSet_test
    {
        
        [Test]
        public void test_Count ()
        {
            WSet<long> set = new HashSet<long>();

            Assert.AreEqual(0, set.Count);

            set.Include(3333333333333333333);
            Assert.AreEqual(1, set.Count);

            set.Include(4444444444444444444);
            Assert.AreEqual(2, set.Count);

            set.Include(5555555555555555555);
            Assert.AreEqual(3, set.Count);

            set.Exclude(3333333333333333333);
            Assert.AreEqual(2, set.Count);

            set.Exclude(5555555555555555555);
            Assert.AreEqual(1, set.Count);

            set.Exclude(4444444444444444444);
            Assert.AreEqual(0, set.Count);
        }


        [Test]
        public void test_Basic()
        {
            WSet<long> set = new HashSet<long>();

            set.Include(33L);
            set.Include(44L);

            Assert.IsTrue(set.Contains(33L));
            Assert.IsTrue(set.Contains(44L));

            Assert.IsFalse(set.Contains(99L));
            Assert.IsFalse(set.Contains(0));

            set.Exclude(33L);

            Assert.IsFalse(set.Contains(33L));
            Assert.IsTrue(set.Contains(44L));

            set.Exclude(44L);

            Assert.IsFalse(set.Contains(33L));
            Assert.IsFalse(set.Contains(44L));
        }

        
        [Test]
        public void test_Include_Same()
        {
            WSet<long> set = new HashSet<long>();

            set.Include(5);            

            Assert.AreEqual(1, set.Count);
            Assert.IsTrue(set.Contains(5));

            set.Include(5);            

            Assert.AreEqual(1, set.Count);
            Assert.IsTrue(set.Contains(5));
        }

        
        [Test]
        public void test_Exclude_Absent()
        {
            WSet<long> set = new HashSet<long>();

            set.Include(3);            
            set.Include(7);            

            Assert.AreEqual(2, set.Count);

            set.Exclude(5);

            Assert.AreEqual(2, set.Count);
            Assert.IsFalse(set.Contains(5));

            Assert.IsTrue(set.Contains(3));
            Assert.IsTrue(set.Contains(7));
        }


        [Test]
        public void test_Random()
        {
            const int N = 60000;

            WSet<byte> set = new HashSet<byte>();

            Random rndGen = new Random();

            for (int i = 1; i <= N; i++)
            {
                byte item = (byte) rndGen.Next(0, 256);

                if (rndGen.Next(0,2) == 0)
                    set.Include(item);
                else
                    set.Exclude(item);
            }
        }
        
    }
}